package secu;

import java.util.function.Consumer;

import org.apache.commons.codec.digest.HmacAlgorithms;
import org.apache.commons.codec.digest.HmacUtils;

/**
 * commons-codec下的HmacUtils
 * @author ben
 * @date 2021-09-26 23:05:44 CST
 */
public class TestHmacUtils {

	public static Consumer<Object> cs = System.out::println;

	public static void main(String[] args) {
		test1();
	}
	
	/**
	 * HmacUtils基本使用
	 * @author ben
	 * @date 2021-09-26 23:07:00 CST
	 */
	public static void test1() {
		cs.accept("test1()...start");
		
		final String ptext = "abc";
		final String pkey = "key";
		
//		String ret = HmacUtils.hmacSha1Hex(pkey, ptext);
		String ret = new HmacUtils(HmacAlgorithms.HMAC_SHA_1, pkey).hmacHex(ptext);
		cs.accept("ret(sha1)=" + ret);
//		ret = HmacUtils.hmacSha256Hex(pkey, ptext);
		ret = new HmacUtils(HmacAlgorithms.HMAC_SHA_256, pkey).hmacHex(ptext);
		cs.accept("ret(sha256)=" + ret);
//		ret = HmacUtils.hmacSha512Hex(pkey, ptext);
		ret = new HmacUtils(HmacAlgorithms.HMAC_SHA_512, pkey).hmacHex(ptext);
		cs.accept("ret(sha512)=" + ret);
	}

}
